const db = require('../dbbase/db');
const uid = require("node-uuid");
const moment = require('moment');

//添加 涂装 点检设备
exports.addPlantCheckDevices = (req, res, next) => {
    try {
        const device = req.body.device;
        console.log(device);
        const date = moment().format('YYYY-MM-DD HH:mm:ss');
        const sql = "insert into check_device_plant(deviceName,farmName,farmID,productlineID,productLineName,createTime) VALUES(?, ?, ?, ?, ?, ?)";
        const params = [device.deviceName,device.farmName,device.farmID,device.productLineID,device.productLineName,date];
        db.query(sql, params).then((result) => {
            res.status(200).json(result)
        }).catch((err) => {
            console.log(err);
        });
    } catch (err) {
        next(err)
    }
}
//获取 涂装 点检设备
exports.getPlantCheckDeviceList = (req, res, next) => {
    try {
        const sql = "select * from check_device_plant";
        const params = [];
        db.query(sql, params).then((result) => {
            res.status(200).json(result)
        }).catch((err) => {
            console.log(err);
        });
    } catch (err) {
        next(err)
    }
}
//添加 机加工 点检设备
exports.addMachineCheckDevice = async (req, res, next) => {
    try {
        //1.获取请求数据
        const device = req.body.device;
        console.log(device);
        //2.查询设备是否存在。

        // const dsql = "select deviceId from check_device_machine where deviceName='"+ device.deviceName +"' ";
        
        // const deviceId = await db.query(dsql, [])

        // if(deviceId.length){

        // }else{

        // }

        //3.添加设备
        const date = moment().format('YYYY-MM-DD HH:mm:ss');
        const sql = "insert into check_device_machine(deviceName,farmName,farmID,productlineID,productLineName,createTime) VALUES( ?, ?, ?, ?, ?, ?)";
        const params = [device.deviceName,device.farmName,device.farmID,device.productLineID,device.productLineName,date];
        db.query(sql, params).then((result) => {
            res.status(200).json(result)
        }).catch((err) => {
            console.log(err);
        });
    } catch (err) {
        next(err)
    }
}
//获取 机加工点 检设备
exports.getMachineDeviceList =  (req, res, next) => {
    try {
        const sql = "select * from check_device_machine";
        const params = [];
        db.query(sql, params).then((result) => {
            res.status(200).json(result)
        }).catch((err) => {
            console.log(err);
        });
    } catch (err) {
        next(err)
    }
}
//添加 铸造 点检设备
exports.addFoundyCheckDevice =  (req, res, next) => {
    try {
        //1.获取请求数据
        const device = req.body.device;
        console.log(device);
        const date = moment().format('YYYY-MM-DD HH:mm:ss');
        const sql = "insert into check_device_foundy(deviceName,farmName,farmID,productlineID,productLineName,createTime) VALUES(?, ?, ?, ?, ?, ?)";
        const params = [device.deviceName,device.farmName,device.farmID,device.productLineID,device.productLineName,date];
        db.query(sql, params).then((result) => {
            res.status(200).json(result)
        }).catch((err) => {
            console.log(err);
        });
    } catch (err) {
        next(err)
    }
}
//获取 铸造 点检设备
exports.getFoundyDeviceList =  (req, res, next) => {
    try {
        const sql = "select * from check_device_foundy";
        const params = [];
        db.query(sql, params).then((result) => {
            res.status(200).json(result)
        }).catch((err) => {
            console.log(err);
        });
    } catch (err) {
        next(err)
    }
}








